import { createRouter, createWebHashHistory } from "vue-router";

export const Layout = () => import("@/layout/index.vue");

// 静态路由
export const constantRoutes = [
  {
    path: "/redirect",
    component: Layout,
    meta: { hidden: true },
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue"),
      },
    ],
  },
  //用户模块路由
  {
    path: "/users",
    component: Layout,
    redirect: "/users/list",
    name: "users",
    meta: {
      title: "用户管理模块",
      icon: "user",
      hidden: false,
      alwaysShow: false,
      params: null,
    },
    children: [
      {
        path: "list",
        component: () => import("@/views/users/list.vue"),
        name: "userList",
        meta: {
          title: "用户列表管理",
          icon: "el-icon-User",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "info",
        component: () => import("@/views/users/info.vue"),
        name: "userInfo",
        meta: {
          title: "用户个人中心",
          icon: "role",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
    ]
  },


//设备档案管理
  {
  path: "/device",
  component: Layout,
  redirect: "/device/list",
  name: "device",
  meta: {
    title: "设备档案管理",
    icon: "device",
    hidden: false,
    alwaysShow: false,
  },
  children: [
    {
      path: "list",
      component: () => import("@/views/device/list.vue"),
      name: "deviceList",
      meta: {
        title: "设备列表",
        icon: "list",
        keepAlive: true,
      },
    },
    {
      path: "create",
      component: () => import("@/views/device/create.vue"),
      name: "deviceCreate",
      meta: {
        title: "新增设备",
        icon: "add",
        hidden: true,
      },
    },
    {
      path: "edit/:id",
      component: () => import("@/views/device/edit.vue"),
      name: "deviceEdit",
      meta: {
        title: "编辑设备",
        icon: "edit",
        hidden: true,
      },
      props: true,
    },
    {
      path: "detail/:id",
      component: () => import("@/views/device/detail.vue"),
      name: "deviceDetail",
      meta: {
        title: "设备详情",
        icon: "detail",
        hidden: true,
      },
      props: true,
    }
  ],
},

// 客户管理
{
  path: "/customer",
  component: Layout,
  redirect: "/customer/index",
  name: "customer",
  meta: {
    title: "客户管理",
    icon: "user",
    hidden: false,
    alwaysShow: false,
  },
  children: [
    {
      path: "index",
      component: () => import("@/views/system/customer/index.vue"),
      name: "customerIndex",
      meta: {
        title: "客户管理",
        icon: "user",
        keepAlive: true,
      },
    },
  ],
},

// 账单管理
{
  path: "/bill",
  component: Layout,
  redirect: "/bill/index",
  name: "bill",
  meta: {
    title: "账单管理",
    icon: "document",
    hidden: false,
    alwaysShow: false,
  },
  children: [
    {
      path: "index",
      component: () => import("@/views/system/bill/index.vue"),
      name: "billIndex",
      meta: {
        title: "账单管理",
        icon: "document",
        keepAlive: true,
      },
    },
  ],
},

// 计费管理
{
  path: "/billing",
  component: Layout,
  redirect: "/billing/index",
  name: "billing",
  meta: {
    title: "计费管理",
    icon: "money",
    hidden: false,
    alwaysShow: false,
  },
  children: [
    {
      path: "index",
      component: () => import("@/views/system/billing/index.vue"),
      name: "billingIndex",
      meta: {
        title: "计费管理",
        icon: "money",
        keepAlive: true,
      },
    },
  ],
},

// 站点与区域管理
{
  path: "/site",
  component: Layout,
  redirect: "/site/index",
  name: "site",
  meta: {
    title: "站点与区域管理",
    icon: "menu",
    hidden: false,
    alwaysShow: false,
  },
  children: [
    {
      path: "index",
      component: () => import("@/views/system/site/index.vue"),
      name: "siteIndex",
      meta: {
        title: "站点与区域管理",
        icon: "menu",
        keepAlive: true,
      },
    },
  ],
},
  
  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/",
    name: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        component: () => import("@/views/dashboard/index.vue"),
        name: "Dashboard",
        meta: {
          title: "dashboard",
          icon: "homepage",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "401",
        component: () => import("@/views/error/401.vue"),
        meta: { hidden: true },
      },
      {
        path: "404",
        component: () => import("@/views/error/404.vue"),
        meta: { hidden: true },
      },
      {
        path: "profile",
        name: "Profile",
        component: () => import("@/views/profile/index.vue"),
        meta: { title: "个人中心", icon: "user", hidden: true },
      },
      {
        path: "my-notice",
        name: "MyNotice",
        component: () => import("@/views/system/notice/components/MyNotice.vue"),
        meta: { title: "我的通知", icon: "user", hidden: true },
      },
    ],
  },
];

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes,
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

// 全局注册 router
export function setupRouter(app) {
  app.use(router);
}

export default router;